:root {
    --border-radius: 12px;
    --transition-speed: 0.3s;
}

/* Light Mode (Default) */
:root {
    --primary-color: #ff7eb3;
    --secondary-color: #ff758c;
    --bg-color: #f4f7f6;
    --card-bg: rgba(255, 255, 255, 0.7);
    --text-color: #2c3e50;
    --text-muted: #7f8c8d;
    --glass-border: 1px solid rgba(255, 255, 255, 0.8);
    --glass-shadow: 0 4px 16px rgba(0, 0, 0, 0.05);
    --input-bg: #ffffff;
    --input-border: #dfe6e9;
    --navbar-bg: rgba(255, 255, 255, 0.85);
    --table-border: rgba(0, 0, 0, 0.05);
    --hover-bg: rgba(0, 0, 0, 0.03);
}

/* Dark Mode */
body.dark-mode {
    --primary-color: #ff7eb3;
    --secondary-color: #ff758c;
    --bg-color: #1a1a2e;
    --card-bg: rgba(255, 255, 255, 0.1);
    --text-color: #ffffff;
    --text-muted: #a0a0a0;
    --glass-border: 1px solid rgba(255, 255, 255, 0.2);
    --glass-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
    --input-bg: rgba(0, 0, 0, 0.2);
    --input-border: rgba(255, 255, 255, 0.2);
    --navbar-bg: rgba(26, 26, 46, 0.8);
    --table-border: rgba(255, 255, 255, 0.1);
    --hover-bg: rgba(255, 255, 255, 0.05);
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    padding: 0;
    min-height: 100vh;
}

body.dark-mode {
    background-image: radial-gradient(circle at 50% 50%, #2a2a4e 0%, #1a1a2e 100%);
}

.navbar {
    background: var(--navbar-bg);
    backdrop-filter: blur(10px);
    border-bottom: var(--glass-border);
    padding: 0.8rem 2rem;
    position: fixed;
    top: 0;
    width: 100%;
    z-index: 1000;
    box-sizing: border-box;
}

.navbar-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
}

.navbar-brand {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--primary-color);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

.navbar-menu {
    display: flex;
    gap: 2rem;
    flex-grow: 1;
    justify-content: center;
    padding-left: 10%;
}

.navbar-item {
    color: var(--text-color);
    text-decoration: none;
    font-weight: 500;
    cursor: pointer;
    font-size: 1.05rem;
}

.navbar-item:hover,
.navbar-item.active {
    color: var(--primary-color);
}

.theme-toggle {
    background: none;
    border: none;
    color: var(--text-color);
    cursor: pointer;
    font-size: 1.2rem;
    padding: 0.5rem;
    transition: transform 0.3s;
}

.theme-toggle:hover {
    transform: rotate(15deg);
}

.container {
    max-width: 1200px;
    margin: 80px auto 2rem;
    padding: 0 1rem;
}

.card {
    background: var(--card-bg);
    backdrop-filter: blur(8px);
    border: var(--glass-border);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    box-shadow: var(--glass-shadow);
    margin-bottom: 1.5rem;
    transition: background var(--transition-speed), border-color var(--transition-speed);
}

.card-header {
    font-size: 1.25rem;
    font-weight: bold;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--table-border);
    padding-bottom: 0.5rem;
}

.form-group {
    margin-bottom: 0.5rem;
}

.form-control {
    width: 100%;
    padding: 0.6rem;
    border-radius: 8px;
    border: 1px solid var(--input-border);
    background: var(--input-bg);
    color: var(--text-color);
    font-size: 0.95rem;
    transition: border-color 0.3s, background var(--transition-speed);
    box-sizing: border-box;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
}

.btn {
    padding: 0.6rem 1.2rem;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-weight: 600;
    transition: transform 0.2s, box-shadow 0.2s;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    white-space: nowrap;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(255, 117, 140, 0.4);
}

.btn-secondary {
    background: var(--input-bg);
    color: var(--text-color);
    border: 1px solid var(--input-border);
}

.btn-secondary:hover {
    background: var(--hover-bg);
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 0.5rem;
    table-layout: fixed;
    /* Enforce fixed column widths */
}

th,
td {
    padding: 0.8rem;
    text-align: left;
    border-bottom: 1px solid var(--table-border);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

th {
    font-weight: 600;
    color: var(--primary-color);
}

tr:hover {
    background: var(--hover-bg);
}

.pagination {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-top: 1.5rem;
}

.layout-grid {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.grid-compact {
    display: grid;
    gap: 0.8rem;
    align-items: end;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fade-in {
    animation: fadeIn 0.5s ease-out forwards;
}

/* Mobile Responsive Styles */
@media (max-width: 768px) {
    .layout-grid {
        grid-template-columns: 1fr;
    }

    .navbar-container {
        grid-template-columns: 1fr !important;
        gap: 0.5rem;
        padding: 0.5rem;
    }

    .navbar-brand {
        justify-content: center;
        margin-bottom: 0.5rem;
    }

    .navbar-menu {
        justify-content: center !important;
        padding-left: 0 !important;
        gap: 1rem !important;
        flex-wrap: wrap;
    }

    .navbar-item {
        font-size: 0.9rem;
    }

    .grid-compact {
        grid-template-columns: 1fr !important;
    }

    .form-group[style*="grid-column: span 2"] {
        grid-column: span 1 !important;
    }

    .container {
        margin-top: 220px;
        /* Increased margin to prevent overlap */
    }

    /* Fix table width on mobile */
    table {
        table-layout: auto;
    }

    th,
    td {
        padding: 0.5rem;
        font-size: 0.85rem;
        white-space: nowrap;
        overflow: visible;
        text-overflow: clip;
    }

    /* Set min-width for columns to force horizontal scroll */
    th:nth-child(1),
    td:nth-child(1) {
        min-width: 50px;
    }

    /* Rank */
    th:nth-child(2),
    td:nth-child(2) {
        min-width: 150px;
    }

    /* Clan Name */
    th:nth-child(3),
    td:nth-child(3) {
        min-width: 100px;
    }

    /* Score */
    th:nth-child(4),
    td:nth-child(4) {
        min-width: 60px;
    }

    /* Members */
    th:nth-child(5),
    td:nth-child(5) {
        min-width: 120px;
    }

    /* Leader */
    th:nth-child(6),
    td:nth-child(6) {
        min-width: 80px;
    }

    /* Lap */
    th:nth-child(7),
    td:nth-child(7) {
        min-width: 80px;
    }

    /* Previous */
}

/* Desktop Table Column Widths */
@media (min-width: 769px) {
    th:nth-child(1) {
        width: 80px;
    }

    /* 排名 */
    th:nth-child(2) {
        width: 220px;
    }

    /* 公会名 */
    th:nth-child(3) {
        width: 150px;
    }

    /* 分数 */
    th:nth-child(4) {
        width: 80px;
    }

    /* 人数 */
    th:nth-child(5) {
        width: 220px;
    }

    /* 会长名 */
    th:nth-child(6) {
        width: 100px;
    }

    /* 参考周目 */
    th:nth-child(7) {
        width: 100px;
    }

    /* 上期 */
}